﻿Imports System.Windows.Forms

Public Class FindDialog

    Dim pForm As frmMain

    Public Sub ActiveRTF()
        pForm.rtfText.Focus()
        pForm.rtfText.Select()
    End Sub

    Private Sub RefreshFindItems()
        If aFindItems.IndexOf(txtFind.Text) >= 0 Then
            aFindItems.RemoveAt(aFindItems.IndexOf(txtFind.Text))
        End If
        aFindItems.Add(txtFind.Text)

        If aFindItems.Count > 15 Then
            Dim tmpFindItems As New ArrayList
            For i = 0 To 14
                tmpFindItems.Add(aFindItems(i))
            Next
            aFindItems = tmpFindItems
        End If

        RefershComboItems()
    End Sub

    Private Sub RefershComboItems()
        txtFind.Items.Clear()
        For Each Item In aFindItems
            txtFind.Items.Add(Item)
        Next
    End Sub

    Private Sub FindDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        pForm = DirectCast(frmMDIParent.ActiveMdiChild, frmMain)
        Me.txtFind.Text = pForm.GetCurrentWord.WordContext
        Me.TopMost = True
        RefreshFindItems()

        pForm.rtfAltKey = False
        pForm.rtfCtrlKey = False
    End Sub

    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
        Me.Close()
        ActiveRTF()
    End Sub

    Private Sub cmdGPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGPrev.Click
        'pForm.cmdFindPrev_Click()
        pForm.GFindPrev(txtFind.Text)
        RefreshFindItems()
        ActiveRTF()
    End Sub

    Private Sub cmdGNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGNext.Click
        'pForm.cmdFindNext_Click()
        pForm.GFindNext(txtFind.Text)
        RefreshFindItems()
        ActiveRTF()
    End Sub

    Private Sub cmdSNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSNext.Click
        pForm.SFindNext(txtFind.Text)
        RefreshFindItems()
        ActiveRTF()
    End Sub

    Private Sub txtFind_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles txtFind.DragEnter
        If (e.Data.GetDataPresent(DataFormats.Text)) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub txtFind_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles txtFind.DragDrop
        txtFind.Text = e.Data.GetData(DataFormats.Text)
    End Sub

    Private Sub txtFind_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFind.SelectedIndexChanged

    End Sub

End Class
